package com.stx.mall.service.impl;

import com.stx.mall.dao.UserDAO;
import com.stx.mall.model.User;
import com.stx.mall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDAO userDAO;

    @Override
    public User login(String username, String password) {
        User user = userDAO.findByName(username);
        if(user == null){
            return null;
        }
        if (user.getPassword().equals(password)){
            return user;
        }
        return null;
    }

    @Override
    public boolean register(User user) {
        userDAO.insert(user);
        return true;
    }

    @Override
    public List<User> findAllUsers() {
        return userDAO.findAll();
    }

    @Override
    public boolean isExist(String uname) {
        User user = userDAO.findByName(uname);
        if(user == null){
            return false;
        }
        return true;
    }
}
